#region License
// KaqazAuthentication.cs
// 
// Copyright (c) 2012 Xoqal.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

namespace Kaqaz.Data
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class KaqazAuthentication : Xoqal.Security.Authentication
    {
        private readonly Data.IUserRepository userRepository;
        
        /// <summary>
        /// Initializes a new instance of the <see cref="KaqazAuthentication"/>.
        /// </summary>
        /// <param name="userRepository"></param>
        public KaqazAuthentication(Data.IUserRepository userRepository)
        {
            this.userRepository = userRepository;
        }
        
        /// <summary>
        /// Gets the user.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        protected override Xoqal.Security.IUser GetUser(string name, string password)
        {
            return this.userRepository.GetUser(name, password);
        }

        /// <summary>
        /// Gets the user.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        protected override Xoqal.Security.IUser GetUser(string name)
        {
            return this.userRepository.GetUser(name);
        }

        /// <summary>
        /// Gets the user by name or email.
        /// </summary>
        /// <param name="nameOrEmail">The name or email.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        protected override Xoqal.Security.IUser GetUserByNameOrEmail(string nameOrEmail, string password)
        {
            return this.userRepository.GetUserByUserNameOrEmail(nameOrEmail, password);
        }

        /// <summary>
        /// Updates the user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected override void UpdateUser(Xoqal.Security.IUser user)
        {
            this.userRepository.Update((Entities.User)user);
        }
    }
}
